<style>
    .footer.footer-home {display: none;}
    #my-order-page{margin-top: 0;}
    .order-select{margin-top:0;margin-bottom: 1rem;}
</style>
<div id="my-order-page">
<!--<div class="header">
    <a href="index.php?act=member" class="return iconfont icon-shangyiye"></a>
    <div class="header-title">我的订单</div>
</div>-->
<div class="order-select">
    <ul>
        <li>
            <a href="index.php?act=member&op=order" class="<?php echo $output['state'] == 0?'green':''; ?>">
                <i class="iconfont icon-jilu"></i>
                <p>全部</p>
            </a>
        </li>
        <li>
            <a href="index.php?act=member&op=order&state=1" class="<?php echo $output['state'] == 1?'green':''; ?>">
                <i class="iconfont icon-qianbao"></i>
                <p>待支付</p>
            </a>
        </li>
        <li>
            <a href="index.php?act=member&op=order&state=2" class="<?php echo $output['state'] == 2?'green':''; ?>">
                <i class="iconfont icon-youhuiquan"></i>
                <p>待使用</p>
            </a>
        </li>
        <li>
            <a href="index.php?act=member&op=order&state=3" class="<?php echo $output['state'] == 3?'green':''; ?>">
                <i class="iconfont icon-yiwancheng"></i>
                <p>已完成</p>
            </a>
        </li>
        <li>
            <a href="index.php?act=member&op=order&state=4" class="<?php echo $output['state'] == 4?'green':''; ?>">
                <i class="iconfont icon-yiquxiao"></i>
                <p>已取消</p>
            </a>
        </li>
    </ul>
</div>

<div class="order-list" style="margin-bottom: 5rem;">
    <ul>
        <?php if (!empty($output['orders'])): ?>
        <?php foreach ($output['orders'] as $order): ?>
        <li style="margin-bottom: 1rem;">
            <div class="list-top line">
                <span class="left"><?php echo $output['order_type'][$order['order_type']]?><?php //echo $order['order_sn']; ?></span>
                <span class="right green fr"><?php echo $output['status'][$order['order_status']]; ?></span>
            </div>
                <?php if($order['order_type']==1){ ?>
                    <!-- 酒店 -->
                    <?php foreach ($order['sku'] as $sku): ?>
                    <a href="index.php?act=member&op=orderdetail&ordersn=<?php echo $order['order_sn']; ?>">
                        <div class="list-mid">
                            <div class="list-img">
                                <img src="<?php echo $order['ticket_thumb']; ?>" />
                            </div>
                            <div class="list-info">
                                <p class="title"><?php echo $order['ticket_title'] ?></p>
                                <p class="code">房型:<?php echo $order['spec_name']; ?></p>
                                <div><span>¥</span><?php echo $sku['unit_price']; ?><span> /间</span> <span class="fr">×<?php echo $sku['oh_num']; ?></span></div>
                                <p class="code">核销码:<?php echo $order['ticket_code']; ?></p>
                            </div>
                        </div>
                    </a>
                    <?php endforeach; ?>
                <?php }elseif($order['order_type']==2){ ?>
                    <!-- 门票 -->
                    <?php foreach ($order['sku'] as $sku): ?>
                        <a href="index.php?act=member&op=orderdetail&ordersn=<?php echo $order['order_sn']; ?>">
                            <div class="list-mid">
                                <div class="list-img">
                                    <img src="<?php echo $order['ticket_thumb']; ?>" />
                                </div>
                                <div class="list-info">
                                    <p class="title"><?php echo $order['ticket_title'] ?></p>
                                    <div><span>¥</span><?php echo $sku['ot_price']; ?><span> / 张</span> <span class="fr">×<?php echo $sku['ot_num']; ?></span></div>
                                    <p class="code">取票码:<?php echo $order['ticket_code']; ?></p>
                                </div>
                            </div>
                        </a>
                    <?php endforeach; ?>
                <?php }else {?>
                    <!-- 美食 -->
                    <?php foreach ($order['sku'] as $sku): ?>
                        <a href="index.php?act=member&op=orderdetail&ordersn=<?php echo $order['order_sn']; ?>">
                            <div class="list-mid">
                                <div class="list-img">
                                    <img src="<?php echo $order['ticket_thumb']; ?>" />
                                </div>
                                <div class="list-info">
                                    <p class="title"><?php echo $order['ticket_title'] ?></p>
                                    <div><span>¥</span><?php echo $sku['og_price']; ?><span> / 份</span> <span class="fr">×<?php echo $sku['og_num']; ?></span></div>
                                    <p class="code">取票码:<?php echo $order['ticket_code']; ?></p>
                                </div>
                            </div>
                        </a>
                    <?php endforeach; ?>
                <?php } ?>
            <div class="list-bot line">
                <samp>合计：</samp><span>¥<?php echo $order['need_pay']; ?></span>
                <?php if ($order['order_status'] == 10): ?>
               <a href="javascript:callpay('<?php echo $order['order_sn']; ?>');" class="btn1 fr pay">立即支付</a>
                <a href="javascript:cancel('<?php echo $order['order_sn']; ?>');" class="btn1 fr">取消订单</a>
                <?php elseif($order['order_status'] == 21 && $order['if_comment'] ==0): ?>
                    <a href="index.php?act=order&op=add_comment&order_sn=<?php echo $order['order_sn']; ?>" class="btn1 fr">评价订单</a>
                <?php elseif($order['order_status']==20 ): ?>
                    <a href="index.php?act=order&op=refund&order_sn=<?php echo $order['order_sn']; ?>" class="btn1 fr">申请退款</a>
                <?php endif; ?>
            </div>
        </li>
        <?php endforeach; ?>
        <?php else: ?>
            <div class="empty">暂无内容</div>
        <?php endif; ?>
    </ul>
    <div class="load hide">正在加载...</div>
</div>

</div>
<div class="mask" style="display: none;">
    <div class="payway" onclick=" event.stopPropagation();">
        <p>支付选择：</p>
        <ul>
            <li>
                <a  class="pay_type_button" >
                    <label for="radio1" >
                        <i class="zf zfb"></i>
                        支付宝支付
                        <input type="radio" name="zf" id="radio1" value="ali" class="radio-btn"/>
                        <i class="radio"></i>
                    </label>
                </a>
            </li>
          <li>
                <a  class="pay_type_button">
                    <label for="radio2">
                        <i class="zf wx"></i>
                        微信支付
                        <input type="radio" name="zf" id="radio2" class="radio-btn" value="wx"/>
                        <i class="radio"></i>
                    </label>
                </a>
            </li>
        </ul>
        <input type="hidden" name="order_code" value="">
        <input type="hidden" name="pay_type" value="">
        <a href="javascript:;" class="submit-btn">确认提交支付</a>
    </div>

</div>
<link rel="stylesheet" href="resource/css/payway.css?v=0.12" />
<script>
    //取消订单
    function cancel(ordersn) {
        popConfirm('确定要取消订单？', function () {
            $.post('index.php?act=order&op=cancel', {ordersn: ordersn}, function (data) {
                if (data.errcode == 0) {
                    location.reload();
                } else {
                    popAlert(data.errmsg);
                }
            }, 'json');
        });
    }

    //支付
    function jsApiCall(json){
        WeixinJSBridge.invoke('getBrandWCPayRequest', json, function (res) {
            if (res.err_msg == 'get_brand_wcpay_request:ok') {
                location.href = 'index.php?act=member&op=order';
            } else {
                popAlert('支付失败,请稍后重新支付', function () {
                    location.href = 'index.php?act=member&op=order';
                });
            }
        });
    }

    //是否正在支付
    var paying = false;
    <!-- 判断是否微信 -->
    <?php if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false): ?>
    //发起支付(公众号)
    function callpay(orderSn) {
        if (paying) {
            popAlert('请不要重复支付');
            return false;
        }
        paying = true;
        $.post('index.php?act=order&op=pay', {order_sn:orderSn},function (data) {
            if (data.errcode == 0) {
                if (data.errmsg == false) {
                    popAlert('支付错误');
                } else {
                    jsApiCall(data.errmsg);
                }
            } else {
                popAlert(data.errmsg, function () {
                    location.reload();
                });
            }
        }, 'json');
    }
    <?php else: ?>
    function callpay(orderSn){
        $('.mask').show();
        $("[name='order_code']").val(orderSn);
    }
    //$('.mask').show();
 /*   function callpay(orderSn) {
        if (paying) {
            popAlert('请不要重复支付');
            return false;
        }
        paying = true;

        //APP内这边要先弹出选择的支付方式

        $.post('index.php?act=order&op=pay&t=ali', {order_sn:orderSn},function (data) {
            if (data.errcode == 0) {
                if (data.errmsg == false) {
                    popAlert('支付错误');
                } else {
                    window.app && window.app.AppPay(data.errmsg);
                    window.webkit && window.webkit.messageHandlers.AppPay.postMessage(data.errmsg);
                }
            } else {
                popAlert(data.errmsg, function () {
                    location.reload();
                });
            }
        }, 'json');
    }*/
    <?php endif; ?>
    function alipay(orderSn){

        $.post('index.php?act=order&op=pay&t=ali', {order_sn:orderSn},function (data) {
            if (data.errcode == 0) {
                if (data.errmsg == false) {
                    popAlert('支付错误');
                } else {

                    window.app && window.app.AppPay(data.errmsg);
                    window.webkit && window.webkit.messageHandlers.AppPay.postMessage(data.errmsg);
                }
            } else {
                popAlert(data.errmsg, function () {
                    location.reload();
                });
            }
        }, 'json');

    }

    function  wxpay(orderSn){

        $.post('index.php?act=order&op=pay&t=wx', {order_sn:orderSn},function (data) {

            if (data.errcode == 0) {
                if (data.errmsg == false) {
                    popAlert('支付错误');
                } else {

                    //alert(JSON.stringify(data.errmsg));
                    window.app && window.app.AppWxPay(JSON.stringify(data.errmsg));
                    window.webkit && window.webkit.messageHandlers.AppWxPay.postMessage(JSON.stringify(data.errmsg));
                }
            } else {
                popAlert(data.errmsg, function () {
                    location.reload();
                });
            }
        }, 'json');

   }

   $('.mask').click(function(){
       $('.mask').hide();
   })

    $('.pay_type_button').click(function(){
        var pay_type= $(this).find('input').val();
        $("[name='pay_type']").val(pay_type);
    });
    $('.submit-btn').click(function(){
        var order_code = $("[name='order_code']").val();
        if($("[name='pay_type']").val()==''){
            alert('请选择您的支付方式！');
            return;
        }
       if($("[name='pay_type']").val() == 'ali'){
           //支付宝支付
           alipay(order_code);
       }
        if($("[name='pay_type']").val() == 'wx'){
            //微信支付
            wxpay(order_code);
        }
    })
    var allNum = <?php echo $output['TotalNum']; ?>,
        allPage = <?php echo $output['TotalPage']; ?>,
        curPage = 1;

    var is_scroll = false;
    //ajax加载数据
    function loadpage() {
        if(!is_scroll){
            return;
        }
        if (curPage < allPage) {
            curPage += 1;
        } else {
            $('.load').text('没有更多内容了').show();
            return;
        }
        $.get(location.href, {isajax:1,curpage:curPage},function(data){
            if(data){
                $(".order-list > ul").append(data);
                $('.load').hide();
            }
        });
    }
    $(window).scroll(function () {
        $('.load').show();
        is_scroll = true;
        //已经滚动到上面的页面高度
        var scrollTop = $(this).scrollTop();
        //页面高度
        var scrollHeight = $(document).height();
        //浏览器窗口高度
        var windowHeight = $(this).height();
        //此处是滚动条到底部时候触发的事件，在这里写要加载的数据，或者是拉动滚动条的操作
        if (scrollTop + windowHeight == scrollHeight) {
            loadpage();
        }
    });
</script>